#include"process.h"

const char *str= "|/-\\";

void process_v1()
{
    // version 1
    int rate = 0;
    char bar[SIZE] = {0};

    
    int num = strlen(str);
        
    while(rate <= MAX_SIZE)
    {
        printf("[%-100s][%d%%][%c]\r", bar, rate, str[rate % num]);
        fflush(stdout);
        usleep(STIME);
        bar[rate++] = STYLE;
    }
    printf("\n");
}

//////////////////////////////////////////////////////////////////////////////////////
void process_v2(double rate)
{    
    static char bar[SIZE] = {0};
    static int cnt = 0;
    
    int num = strlen(str);
        
    if(rate <= MAX_SIZE && rate >= 0)
    {
        cnt++;
        cnt = (cnt > num ? 0 : cnt);
        printf("\033[44m%-100s\033[0m][%.1f%%][%c]\r", bar, rate, str[cnt]);
        fflush(stdout);
        if(rate < MAX_SIZE)
        {
            bar[(int)rate] = STYLE_BODY;
            bar[(int)rate + 1] = STYLE_HEAD;
        }
        else
        {
            bar[(int)rate] = STYLE_BODY;
        }
    }
    if(rate == MAX_SIZE)
    {   
        memset(bar, '\0', sizeof(bar));
    }   
}
